package main.controller;

import main.*;
import main.database.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class ArticleCollectedPageController {
    @GetMapping("/articlecollected")
    public String articleCollectedPage(ModelMap modelMap, HttpServletRequest request) {
        String uuid = RequestHelper.getUserUUIDFromRequest(request);
        boolean isExist = AccountHelper.isExistFromUUID(uuid);
        boolean isAdmin = AccountHelper.isAdminFromUUID(uuid);

        String user = "";
        if (isExist) {
            user = uuid;
        }

        StatisticHelper.addMainPageAccess(uuid, NetworkHelper.getIPAddress(request), TimeHelper.getFormattedNowString(), UserAgentHelper.getUserAgent(request));

        List<String[]> artileList = ArticleHelper.findArtileListFromTime(0);

        long unread = 0;
        if (isExist) {
            unread = NotifyHelper.countUnreadNotify(uuid);
        }

        modelMap.put("siteName", GlobalConfig.siteName);
        modelMap.put("isLogin", isExist);
        modelMap.put("isAdmin", isAdmin);
        modelMap.put("unread", unread);
        modelMap.put("articleList", artileList);
        modelMap.put("year2year", TimeHelper.getFormattedYear2Year());
        return "articleCollectedPage";
    }

}